package cn.ecut.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/header2.do")
public class HeaderServlet2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 设置指定的编码
        response.setCharacterEncoding("UTF-8");
        // 设置 响应头
        response.setHeader("content-type" , "text/html; charset=utf-8");
        response.setDateHeader("date" , 1000);
        // 期望页面上显示出来内容
        PrintWriter writer = response.getWriter();
        // 利用  PrintWriter 的实例，可以向 响应中输出内容
        writer.write("<script>");
        writer.write("console.log('123')");
        writer.write("</script>");
    }
}
